package com.drugmanage.intercepter;

import com.drugmanage.service.IUserService;
import com.drugmanage.utils.AssertUtil;
import com.drugmanage.utils.LoginUserUtil;
import com.drugmanage.utils.ValidateUtil;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class NoAccessIntercepter extends HandlerInterceptorAdapter{

    @Resource
    private IUserService userService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Integer userId = LoginUserUtil.releaseUserIdFromCookie(request);

        AssertUtil.Nologin(ValidateUtil.nullOrZeroInteger(userId),"用户未登录");
        AssertUtil.Nologin(userService.getById(userId)==null,"用户未登录");

        return true;
    }
}
